package com.hongawen.tool.文件类工具.文件拷贝;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author hongawen
 * @version 1.0
 * @data 2025/5/14 10:49
 */
public class 拷贝文件夹所有内容 {
    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        String source = "D:\\Snipaste-1.16.2-x64";
        String target = "D:\\Snipaste-1.16.2-x64aaa";

        try {
            Files.walk(Paths.get(source)).forEach(path -> {
                try {
                    String targetName = path.toString().replace(source, target);
                    // 是目录
                    if (Files.isDirectory(path)) {
                        Files.createDirectory(Paths.get(targetName));
                    }
                    // 是普通文件
                    else if (Files.isRegularFile(path)) {
                        Files.copy(path, Paths.get(targetName));
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            });
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }
}
